/*
** 2015-12-30
** paged file Component
** refer cs.stanford.edu/people/widom/cs346/pf.html
** pager defines page-oriention file operation
**  
*/

#ifndef __PAGER_H__
#define __PAGER_H__

#define PAGE_SZ				512 	/* page size */
#define MAX_CACHE_COUNT		10 	/* max cached page count */

struct Page;
struct PageCache;
struct PageManager;

typedef struct Page* pPage;
typedef struct PageCache* pPageCache;
typedef struct PageManager* pPageManager;

/* open or create db file*/
pPageManager openFile(const char* name);

/* close this db file*/
void closeFile(pPageManager);

/*
** obtain a page for later use, this page pinCount++
** routine of write a page:
**      obtainPage      ->
**      startWritePage  ->
**      flushPage       ->
**      releasePage
**
** routine of read a page:
**      obtainPage      ->
**      releasePage
*/
char* obtainPage(pPageManager, int pageno);

/* append a new page to file */
int appendPage(pPageManager);

/* release page will cause pinCount -1 */
void releasePage(pPageManager, int pageno);

/* 
** declare to write 
** get the write lock and
*/
void startWritePage(pPageManager, int pageno); 

/* after do acturely write, need flush to disk */
void flushPage(pPageManager, int pageno);

/* print info ***/
void printPM(pPageManager pMgr);


#endif
